package com.mskj.zxmy.mapper;


import com.mskj.zxmy.dto.*;
import com.mskj.zxmy.entity.BarcodeManagement;
import com.mskj.zxmy.entity.CKDan;
import com.mskj.zxmy.entity.XssalesDispatchDetails;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;
import java.util.Map;

@Mapper
public interface OutboundOrderMapper {

    /**
     * 查询发货单
     * @return
     */
     List<ShipmentNoticeDTO> outboundOrderList();

    /**
     * 条件查询
     * @param params
     * @return
     */
    List<ShipmentNoticeDTO> selectShipmentNoticeList(Map<String, Object> params);

    /**
     * 分页+多条件筛选发货通知单
     */
    List<ShipmentNoticeDTO> selectShipmentNoticeListByQuery(OutboundOrderListQueryDTO query);

    String selectMaxcashiersNumberByDate(String datePartForRepository);

    String getSalesAndDispatchDetailsIdsByOrderNumber(String shipmentOrderNumber);

    List<XssalesDispatchDetails> getDispatchDetailsByIds(List<Integer> ids);


    int insertCKDan(CKDan ckDan);

    void insertCKDanDetail(CKDanDetailSaveDTO detail);

    /**
     * 查询出库单列表
     * @return
     */
    List<CKDanListDTO> getCKDanList(CKDanListQueryDTO query);

    List<CKDanListDTO> filterCKDanList(Map<String, Object> params);


    CKDanSaveDTO getCKDanByCashiersNumber(String cashiersNumber);

    List<CKDanDetailSaveDTO> getCKDanDetailsByMainId(int id);

    // 查询明细是否已存在
    CKDanDetailSaveDTO getDetailByMainIdAndProductAndBatch(int linkToList, String productInformation, String batchNumber);
    // 合并明细数量
    int updateDetailNumberOfReleases(int id, int addNumber);

    // 同时更新主表的出库数量（numberOfReconciliations）和对账数量（reconciliationAmount1）
    int updateNumberOfReconciliations(String cashiersNumber, int numberOfReconciliations);


    ProductDetailDTO getProductInfo(Integer Id);

    Integer getStockByProductAndBatch(String productId, String detailId);

    void decreaseStock(String productInformation, Integer detailId, Integer numberOfReleases);


    @Select("select nick from corp_member c left join lists l on c.memberId = l.operator where l.cashiersNumber = #{cashiersNumber}")
    String getAssociatedSuppliersName(String cashiersNumber);

//    根据入库明细ID
    @Select("select g.id from ck04ListOfEntriesListOfEntries c left join gy02ProductRepository g on c.productInformation = g.id where  c.id = #{detailId}")
    int getProductInfoOfId(Integer barcode);

    int sumDetailNumberOfReleases(int mainId);

    void updateTotalNumberById(int mainId, int totalNumber);


    String getClientByAssociatedConsignmentOrder(String associatedConsignmentOrder);

    Integer getStockByDetailId(int id);


    // 出库明细列表（按出库状态）
    List<ck02CheckoutFormCheckout>  getOutboundDetails(@Param("documentStatus") String documentStatus);

    // 根据明细id查明细
    ck02CheckoutFormCheckout selectOutboundDetailById(@Param("detailId") String detailId);


    List<ck02CheckoutFormCheckout> selectStockInByProductNumbers(@Param(("cashiersNumber")) String cashiersNumber, @Param("list") List<String> productNumbers, @Param("documentStatus")String documentStatus);

    @Select("select cashiersNumber from lists where id = #{linkOutList}")
    String getLinkOutListByCashiersNumber(String linkOutList);

    @Select("select * from barcodeManagementTable where id = #{id}")
    BarcodeManagement getBarcodeManagementBycode(Integer id);

    void decreaseBarcodeManagement(Integer id, Integer number);


    @Select("select * from ck04ListOfEntriesListOfEntries where batchNumber =#{barcode}")
    CKDanDetailSaveDTO getOutDetail(Integer barcode);
}
